// 
//  Event.m
//  Bango
//

#import "Event.h"

// IMF Imports
#import "EventParameter.h"
#import "Profile.h"
#import "BangoUtils.h"
#import "BangoFieldNames.h"


@implementation Event 

@dynamic eventTime;
@dynamic errorLevel;
@dynamic connectionType;
@dynamic errorId;
@dynamic eventDetail;
@dynamic eventName;
@dynamic eventValue;
@dynamic eventPosted;
@dynamic eventParameters;
@dynamic profile;

// custom code
- (id)proxyForJson {
	
	NSMutableArray *eventsParametersArray = [[NSMutableArray alloc] initWithArray:[self.eventParameters allObjects]];
	
	//NSLog(@"eventsParametersArray %@", eventsParametersArray);
	
	// create dictionary
	NSMutableDictionary *eventsDictionary = [[[NSMutableDictionary alloc] init] autorelease];
	
	NSString *eventTimeUtc = [BangoUtils getUTCDate:self.eventTime];
	NSString *eventLocalTime = [BangoUtils getLocalDate:self.eventTime]; 
	
	// times are mandatory fields
	[eventsDictionary setObject:eventTimeUtc forKey:POST_EVENTTIME];	
	[eventsDictionary setObject:eventLocalTime forKey:POST_EVENTLOCALTIME];
	
	// event name is mandatory
	[eventsDictionary setObject:self.eventName forKey:POST_EVENTNAME];
	
	if(self.eventDetail != nil) {
		[eventsDictionary setObject:self.eventDetail forKey:POST_EVENTDETAIL];
	} else {
		[eventsDictionary setObject:@"" forKey:POST_EVENTDETAIL];
	}
	
	if(self.eventValue != nil) {
		[eventsDictionary setObject:self.eventValue forKey:POST_EVENTVALUE];
	} else {
		[eventsDictionary setObject:@"" forKey:POST_EVENTVALUE];
	}
	
	// set the events parameters
	[eventsDictionary setObject:eventsParametersArray forKey:POST_EVENT_PARAMETERS];
	
	// done with params array now
	[eventsParametersArray release];
	
    return eventsDictionary;
}

@end
